﻿<Page x:Class="SqlMetalIncludeGUI.StartScreen"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:Me="clr-namespace:SqlMetalIncludeGUI"
      xmlns:Settings="clr-namespace:SqlMetalIncludeGUI.Properties"
      WindowTitle="SqlMetalInclude GUI" WindowHeight="700" WindowWidth="900"
      x:Name="_this">
    <Page.Resources>
        <Me:Config x:Key="Config" />
        <Settings:Settings x:Key="Settings" />
    </Page.Resources>
    <DockPanel>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock="Bottom">
            <Button Margin="5" Content="Edit config" x:Name="editConfig" Click="editConfig_Click"
                    Visibility="{Binding ElementName=loadConfigRadio, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
            <Button Margin="5" Content="Load config" x:Name="loadConfigContinue" Click="loadConfigContinue_Click"
                    Visibility="{Binding ElementName=loadConfigRadio, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
            <Button Margin="5" Content="Create config" x:Name="newConfigContinue" Click="newConfigContinue_Click" 
                    Visibility="{Binding ElementName=newConfigRadio, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
            <Button Margin="5" Content="Save" x:Name="savePrefButton" Click="savePrefButton_Click"
                    Visibility="{Binding ElementName=preferencesRadio, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
            <Button Margin="5" Content="Reload" x:Name="reloadButton" Click="reloadButton_Click" 
                    Visibility="{Binding ElementName=preferencesRadio, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
            <RadioButton Content="New configuration" x:Name="newConfigRadio" Margin="5" IsChecked="True" />
            <RadioButton Content="Load configuration" x:Name="loadConfigRadio" Margin="5" />
            <RadioButton Content="Preferences" x:Name="preferencesRadio" Margin="5" />
        </StackPanel>
        <StackPanel>
            <Grid Visibility="{Binding ElementName=preferencesRadio, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="1*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock Text="Config dir: " Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" />
                <DockPanel Grid.Column="1" Grid.Row="0">
                    <Button Content="Browse" DockPanel.Dock="Right" x:Name="browseButton" Click="browseButton_Click" />
                    <TextBox Text="{Binding Source={StaticResource Settings}, Path=Default.ConfigDirectory}" IsReadOnly="True" />
                </DockPanel>
            </Grid>
            <ListBox ItemsSource="{Binding ElementName=_this, Path=ConfigurationFiles}" x:Name="loadList"
                         Visibility="{Binding ElementName=loadConfigRadio, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"
                     MouseDoubleClick="loadList_MouseDoubleClick"/>

            <Grid Visibility="{Binding ElementName=newConfigRadio, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="1*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />

                </Grid.RowDefinitions>
                <TextBlock Text="Project name: " Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" />
                <TextBox Text="{Binding Source={StaticResource Config}, Path=Default.ProjectName, UpdateSourceTrigger=PropertyChanged}" 
                         x:Name="projectName" Grid.Column="1" Grid.Row="0" />
                <CheckBox 
                    Grid.Row="1"
                    Grid.Column="0" 
                    Grid.ColumnSpan="2" 
                    Margin="5" 
                    Content="Exclude new tables by default"
                    ToolTip="If enabled newly discovered tables/views are not included by default."
                    IsChecked="{Binding Source={StaticResource Config}, Path=Default.ExcludeMode, UpdateSourceTrigger=PropertyChanged}"
                    />
            </Grid>
        </StackPanel>
    </DockPanel>
</Page>
